/**
 * @author David Young
 */
package csab.tests;

import static org.junit.Assert.*;

import java.awt.Rectangle;

import org.junit.Test;

import csab.core.Entity;
import csab.core.View;
import csab.tests.utility.TestSprite;

/**
 * Programmatic test for the View class.
 * @author David Young
 */
public class ViewTest {
	/**
	 * Test method for {@link csab.core.View#center(csab.core.Entity)}.
	 */
	@Test
	public final void testCenter() {
		int x = 0, y = 0, w = 1000, h = 1000, screenw = 2000, screenh = 2000;
		View viewport = new View(x,y,w,h,screenw,screenh);
		Entity ent = null;
		ent = new TestSprite();
		ent.setPos(10, 10);
		viewport.center(ent);
		
		//Test x-y (top left corner)
		Rectangle box = viewport.getCollisionBox();
		assertEquals(0, (int)box.getX());
		assertEquals(0, (int)box.getY());
		
		//Test x-y (top right corner)
		ent.setPos(screenw, 0);
		viewport.center(ent);
		assertEquals(screenw - box.width, (int)box.getX());
		assertEquals(0, (int)box.getY());
		
		//Test x-y (bottom right corner)
		ent.setPos(screenw, screenh);
		viewport.center(ent);
		assertEquals(screenw - box.width, (int)box.getX());
		assertEquals(screenh - box.height, (int)box.getY());
		
		//Test x-y (bottom left corner)
		ent.setPos(0, screenh);
		viewport.center(ent);
		assertEquals(0, (int)box.getX());
		assertEquals(screenh - box.height, (int)box.getY());
		
		//Test x axis adjust
		ent.setPos(1001, 0);
		viewport.center(ent);
		assertEquals(501, (int)box.getX());
		assertEquals(0, (int)box.getY());
		
		//Test y axis adjust
		ent.setPos(0, 1001);
		viewport.center(ent);
		assertEquals(0, (int)box.getX());
		assertEquals(501, (int)box.getY());
		
		//Test middle
		ent.setPos(screenw/2, screenh/2);
		viewport.center(ent);
		assertEquals((int)((int)ent.getX() - (int)box.width/2), (int)box.getX());
		assertEquals((int)((int)ent.getY() - (int)box.height/2), (int)box.getY());
	}
	
	/**
	 * Test method for {@link csab.core.View#View(int, int, int, int, int, int)}.
	 */
	@Test
	public final void testView() {
		int x = 0, y = 0, w = 1000, h = 1000, screenw = 2000, screenh = 2000;
		View viewport = new View(x,y,w,h,screenw,screenh);
		Rectangle box = viewport.getCollisionBox();
		assertEquals(box.x, x);
		assertEquals(box.y, y);
		assertEquals(box.width, w);
		assertEquals(box.height, h);
		assertEquals(viewport.getMapwidth(), screenw);
		assertEquals(viewport.getMapheight(), screenh);
	}

}
